﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Profile;
using IronOne.SalesOne.BusinessObjects;
using System.Configuration;
using Facade;
using System.Collections;
using System.Data;

namespace IronOne.SalesOne.SalesOneWeb.ContactManagement
{
    public partial class SpouseDetails : SOSecurityPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                CustomerFacade cFac = new CustomerFacade();

                if (!IsPostBack)
                {
                    ValidateUserCredentials(Request.Url.LocalPath);

                    if (!string.IsNullOrEmpty(Request.UrlReferrer.ToString()))
                    {
                        ViewState["refUrl"] = Request.UrlReferrer.ToString();
                    }

                }

                if (!string.IsNullOrEmpty(Request.QueryString["nid"]))
                {
                    if (Session["na"] != null)
                    {
                        SalesOne.BusinessObjects.NeedsAnalysis na = (SalesOne.BusinessObjects.NeedsAnalysis)Session["na"];

                        //lblProspectId.Text = Session["prospectId"].ToString();
                        lblProspId.Text = "Needs Analysis No";
                        lblProspectId.Text = na.NeedAnalysisNo.ToString();
                        lblName.Text = na.SpName;
                        lblDob.Text = na.SpDob;
                        lblProfession.Text = na.SpProfession;
                        lblId.Text = na.SpId;
                        lblOtherName.Text = na.SpOtherName;
                        lblGender.Text = na.SpGender;


                    }
                }
                else
                {
                    if (Session["prospectId"] != null && Session["cusId"] != null)
                    {
                        string custId = Session["cusId"].ToString();
                        Spouse sp = cFac.GetSpouseForCustomer(custId);

                        lblProspectId.Text = Session["prospectId"].ToString();
                        lblName.Text = sp.Salutation + " " + sp.Initial + " " + sp.Surname;
                        lblDob.Text = sp.DOB;
                        lblProfession.Text = sp.Profession;
                        lblId.Text = sp.IdType + "-" + sp.IdNo;
                        lblOtherName.Text = sp.OtherName;
                        lblGender.Text = sp.Gender;
                    }
                }

                
            }
            catch (Exception ex)
            {
                //lblError.Text = ex.Message;
            }
            
        }

        protected void cancelButton_Click(object sender, EventArgs e)
        {
            try
            {
                Response.Redirect(ViewState["refUrl"].ToString());
            }
            catch (Exception)
            {

            }
            
        }
    }
}
